home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PCGUIA 117
/
PC Guia 117.iso
/
Software
/
Utils
/
Software6
/
Product8
/
feedview-0.9.7-fx.xpi
/
chrome
/
feedview.jar
/
content
/
feedview.js
< prev
next >
Wrap
Text File
|
2005-03-25
|
7KB
|
281 lines
/*
* Original author: Tom Germeau ( http://www.epigoon.com )
* If you want to use/modify this code please
* contact the original author first.
*/
var currSize;
var number ;
/*Notes: xsl:sort select="name"*/
function setFeed()
{
var title = document.getElementsByTagName("h1")[0].textContent;
document.title = document.getElementsByTagName("title")[0].textContent + " " + title;
}
function xmlDate(In){
In = In.replace('Z', '+00:00')
var D = In.replace(/^(\d{4})-(\d\d)-(\d\d)T([0-9:]*)([.0-9]*)(.)(\d\d):(\d\d)$/, '$1/$2/$3 $4 $6$7$8');
//var D = In.replace(/^(\d{4})-(\d\d)-(\d\d)T([0-9:]*)([0-9:]*)([0-9:]*).*$/, '$1/$2/$3 $4 $6');
//var D = In.replace(/^(\d{4})-(\d\d)-(\d\d)T([0-9:]*)([.0-9]*)(.)(\d\d):(\d\d)$/, '$1/$2/$3 $4 $6$7$8');
D = Date.parse(D);
D += 1000*RegExp.$5;
return new Date(D);
}
function setDate(){
try{
var found = false;
divs = document.getElementsByTagName("div");
for(i=0; i<divs.length; i++){
d = divs[i].getAttribute("date");
if(d )
{
found = true;
if(d.indexOf("T"))
d = xmlDate( d );
else
d = new Date( d );
if(d instanceof Date){
if(0)
day = "Today";
else{
day = d.toGMTString();
day = day.substring(0, 11);
}
divs[i].getElementsByTagName("span")[0].textContent = day + " @ " + lead(d.getHours()) + ":" + lead(d.getMinutes());
}
}
}
if(!found){
document.getElementById("switchdate").style.display = "none";
divs = document.getElementsByTagName("div");
for(i=0; i < divs.length; i++)
if(divs[i].getElementsByTagName("span").length > 0 )
if(divs[i].getElementsByTagName("span")[0].getAttribute("class") == "date")
divs[i].getElementsByTagName("span")[0].style.display = "none";
}
}catch(ex){alert(ex);}
}
function fixchars(txt)
{
txt = txt.replace(/ /g, " ");
txt = txt.replace(/&/g, "&");
txt = txt.replace(/>/g, ">");
txt = txt.replace(/</g, "<");
txt = txt.replace(/"/g, "'");
txt = txt.replace(/’/g, "'");
txt = txt.replace(/‘/g, "'");
txt = txt.replace(/—/g, "ù");
txt = txt.replace(/&/g, "&");
return txt;
}
function resize(maxSize, init){
var img = /<img([^>]*)>/g;
var imgArr;
var im;
//number = 0;
sl = document.getElementById("sizeslider");
sl.setAttribute("curpos", maxSize);
if(maxSize == currSize) return;
currSize = maxSize;
try{
divs = document.getElementsByTagName("div");
for(i=0; i<divs.length; i++){
if(init)
{
title = divs[i].getElementsByTagName("a");
if(title.length > 0)
{
title = title[0];
title.textContent = fixchars(title.textContent);
title.textContent = title.textContent.replace(/<([^>]*)>/g, "");
}
}
txt = divs[i].getAttribute("description");
if(txt != null){
txt = fixchars(txt);
txt = txt.replace(/<br[^\>]*>/g, "\n");
txt = txt.replace(/<p[^\>]*>/g, "\n");
/*
txt = txt.replace(/([0-9]+);/g,
function (str, n){
//alert(n);
try{
//0alert("\u151");
//alert( String.fromCharCode(("x" + n)) );
return String.fromCharCode(parseInt(n));
}catch(ex){alert(ex);}
//return "\u8212";
}
);
*/
if(init){
imgArr = new Array();
img.lastIndex = 0;
while((im = img.exec(txt)) != null)
{
src = /\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i;
im[0] = im[0].replace('border=', ''); // fix somtin?
im[0] = im[0].replace('class=', ''); // fix somtin?
imgsrc = src.exec(im[0]);
imgArr.push(imgsrc[1]);
}
var o;
for(im=0; im < imgArr.length; im++){
a = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
a.setAttribute("href", imgArr[im]);
o = document.createElementNS("http://www.w3.org/1999/xhtml", "img");
a.setAttribute("class", "image");
o.setAttribute("src", imgArr[im]);
a.appendChild(o);
divs[i].appendChild(a);
}
}
txt = txt.replace(/<([^>]*)>/g, "");
ar = txt.split(" ");
if(maxSize == 0) txt = "";
if(maxSize < 100 && maxSize != 0){
if(ar.length > maxSize){
txt = "";
for(x=0; x < maxSize ; x++){
txt += ar[x] + " ";
}
txt += " ..." ;
}
}
/*
if( divs[i].getElementsByTagName("p")[0].textContent != txt)
divs[i].getElementsByTagName("p")[0].textContent = txt;
*/
currentP = divs[i].getElementsByTagName("p")[0];
if(currentP != null){
for(pc = currentP.childNodes.length; pc > 0; pc--){
currentP.removeChild(currentP.childNodes[0]);
}
p = txt.split("\n");
for(im=0; im < p.length; im++){
if(p != ""){
a = document.createElementNS("http://www.w3.org/1999/xhtml", "p");
a.textContent = p[im];
currentP.appendChild(a);
}
}
}
}
}
}catch(ex){alert(ex);}
}
function lead(In){
if(In < 10)
return "0" + In;
else return In;
}
function switchdate() {
var s = document.getElementById("switchdate");
divs = document.getElementsByTagName("div");
if(s.getAttribute("show") == "0"){
//s.setAttribute("show", 1);
s.textContent = "Show date";
for(i=0; i < divs.length; i++)
if(divs[i].hasAttribute("date"))
divs[i].getElementsByTagName("span")[0].style.display = "none";
}else {
//s.setAttribute("show", 0);
s.textContent = "Hide date";
for(i=0; i < divs.length; i++)
if(divs[i].hasAttribute("date"))
divs[i].getElementsByTagName("span")[0].style.display = "inline";
}
}
function listObject(obj, s) {
var res = "List: " + obj + "\n";
for(var list in obj) {
if (list.indexOf(s) == -1)
res += list + ", ";
}
alert(res);
}